define( ["dojo/_base/declare", "dojo/ready", "dojo/request", "dojo/json", "dijit/MenuBar",
     "dijit/DropDownMenu", "dijit/PopupMenuBarItem", "dijit/MenuItem", 
     "dijit/MenuBarItem", "dojo/parser", "dijit/_WidgetBase", "dijit/_TemplatedMixin"],
    function(declare, ready, request, json, MenuBar, DropDownMenu, PopupMenuBarItem, 
        MenuItem, MenuBarItem, parser, _WidgetBase, _TemplatedMixin) {
        return declare("my.createMenu", [_WidgetBase, _TemplatedMixin], {

            templateString: 
               "<div>" + 
                "<div data-dojo-type='dijit/MenuBar'>" +
                    "<div data-dojo-type='dijit/PopupMenuBarItem' label='Dashboards'>" +
                    "<div data-dojo-type='dijit/DropDownMenu' data-dojo-attach-point='dashboardMenu'></div>" +
                    "</div>" +
                    "<div data-dojo-type='dijit/MenuBarItem' label='Import Issues' data-dojo-attach-event='onclick: importIssues'></div>" +
                    "<div data-dojo-type='dijit/MenuBarItem' label='Work Issues' data-dojo-attach-event='onclick: workIssues'></div>" +
                "</div>" +
                "</div>" ,


            importIssues: function() {
                window.location = "/importIssues";
            },

            workIssues: function() {
                window.location = "/workIssues";
            },

            update: function() {
          
                request.post('dashboards', {
                    handleAs: "json"}).then(function(data) {
                        for (var i = 0;i < data.length; i++) {
                            record = data[i];
                            registry.byId('dashboardMenu').addChild(new MenuItem({
                                label: record,
                                onClick: function(){
                                    window.location = "/?tab=" + record;
                                }
                            }));
                        }
                    });
                
            }
        });
        ready(function() {
            //parser.parse();
        });

});
